package com.jk.web.webclient;

import com.alibaba.fastjson.JSON;
import com.jk.common.model.LogBean;
import com.jk.common.model.MessageBean;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "ackQueue")
public class WebLogConsumer {

    @RabbitHandler
    public void process(String msg, Channel channel, Message message) {
        try {
            //改成OrderBean     拿过来一个订单序列号  查询一下订单   把值给下面实体bean   一个一个加上  推送到商家

            MessageBean messageBean = JSON.parseObject(msg, MessageBean.class);
            System.out.println("rabbitMQ消费日志"+msg);
            WebSocketServer.sendInfo(messageBean.toString(),"20");
            //告诉服务器收到这条消息已经被当前消费者消费了，可以在队列安全删除，这样后面就不会再重发了，
            //否则消息服务器以为这条消息没处理掉，后续还会再发
            //第二个参数是消息的标识，false只确认当前一个消息收到，true确认所有consumer获得的消息
            System.out.println(message.getMessageProperties().getDeliveryTag());

            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            System.out.println("消费失败");
            e.printStackTrace();
        }

    }
}
